namespace DotNetNuke.UI.WebControls
{
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Runtime.CompilerServices;
    using System.Web.UI;

    public class NodeImage : IStateManager
    {
        private bool _marked;
        private StateBag _state;

        public NodeImage()
        {
            this._marked = false;
        }

        public NodeImage(string NewImageUrl)
        {
            this._marked = false;
            if (this.ImageUrl == null)
            {
                throw new ArgumentNullException();
            }
            ((IStateManager)this).TrackViewState();
            this.ImageUrl = NewImageUrl;
        }

        public void LoadViewState(object state)
        {
            if (state != null)
            {
                ((IStateManager)this.ViewState).LoadViewState(RuntimeHelpers.GetObjectValue(state));
            }
        }

        public object SaveViewState()
        {
            object objectValue = null;
            if (this._state != null)
            {
                objectValue = RuntimeHelpers.GetObjectValue(((IStateManager)this._state).SaveViewState());
            }
            return objectValue;
        }

        //internal void SetDirty()
        //{
        //    if (this._state != null)
        //    {
        //        using (IEnumerator enumerator = this._state.Keys.GetEnumerator())
        //        {
        //            while (enumerator.MoveNext())
        //            {
        //                string key = StringType.FromObject(enumerator.Current);
        //                this._state.SetItemDirty(key, true);
        //            }
        //        }
        //    }
        //}

        internal void SetDirty()
        {
            if (this._state != null)
            {
                IEnumerator enumerator = this._state.Keys.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    string key = StringType.FromObject(enumerator.Current);
                    this._state.SetItemDirty(key, true);
                }                
            }
        }



        public void TrackViewState()
        {
            this._marked = true;
        }

        public string ImageUrl
        {
            get
            {
                string str = string.Empty;
                if (this.ViewState["ImageUrl"] != null)
                {
                    str = StringType.FromObject(this.ViewState["ImageUrl"]);
                }
                return str;
            }
            set
            {
                this.ViewState["ImageUrl"] = value;
            }
        }

        public bool IsTrackingViewState
        {
            get
            {
                return this._marked;
            }
        }

        //public bool System.Web.UI.IStateManager.IsTrackingViewState
        //{
        //    get
        //    {
        //        return this._marked;
        //    }
        //}

        protected StateBag ViewState
        {
            get
            {
                if (this._state == null)
                {
                    this._state = new StateBag(true);
                    if (this.IsTrackingViewState)
                    {
                        ((IStateManager)this._state).TrackViewState();
                    }
                }
                return this._state;
            }
        }
    }
}

